package com.hzy.service;

import com.hzy.dao.RentMapper;
import com.hzy.pojo.Rent;
import com.hzy.utils.MybatisUtil;
import com.hzy.utils.Page;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * @Package: com.hzy.service
 * @ClassName: RentService
 * @Author: 862982795
 * @CreateTime: 2021/06/22 17:47
 * @Description:
 */
public class RentService extends MybatisUtil {
    private final Logger logger = Logger.getLogger(RentService.class);
    //获取SqlSession实例
    SqlSession sqlSession = createSqlSession();
    List<Rent> list;
    int i;

    public List<Rent> getRentListByUserNameAndCarNumAndLimit(Page page) {
        SqlSession sqlSession = createSqlSession();
        try {
            list = sqlSession.getMapper(RentMapper.class).getRentListByUserNameAndCarNumAndLimit(page);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return list;

    }

    public Integer getCount(Page page) {
        SqlSession sqlSession = createSqlSession();
        try {
            i = sqlSession.getMapper(RentMapper.class).getCount(page);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }

    public Integer check(String carNum) {
        try {
            i = sqlSession.getMapper(RentMapper.class).check(carNum);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }


    public Integer add(Rent rent) {
        try {
            i = sqlSession.getMapper(RentMapper.class).add(rent);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }

    public Integer deleteId(Integer id) {
        try {
            i = sqlSession.getMapper(RentMapper.class).deleteId(id);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }

    public Integer updateRent(Rent rent) {
        try {
            i = sqlSession.getMapper(RentMapper.class).updateRent(rent);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }

    public Integer updateStatus(Integer id) {
        try {
            i = sqlSession.getMapper(RentMapper.class).updateStatus(id);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return i;
    }

    public Rent queryRentById(Integer id) {
        Rent rent;
        try {
            rent = sqlSession.getMapper(RentMapper.class).queryRentById(id);
        } finally {
            MybatisUtil.closeSqlSession(sqlSession);
        }
        return rent;
    }

}
